<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Request;
use Yeepay\Yop\Sdk\V1\YopConfig;
use Yeepay\Yop\Sdk\V1\YopRequest;
use Yeepay\Yop\Sdk\V1\YopRsaClient;
use Yeepay\Yop\Sdk\V1\Util\YopSignUtils;
use sandpay\HmPayClient;
use app\admin\model\YeeRepose;
use app\admin\model\Cart;
use app\admin\model\system_config\Payad;
use app\admin\model\exchange\Ordergas;
use app\admin\model\exchange\Ordergoods;
use app\admin\model\exchange\Orderrecharge;
use app\admin\model\exchange\OrderGasInfo;
use app\admin\model\exchange\OrderGoodsInfo;
use app\admin\model\exchange\Order;
use app\admin\model\UserDetail;
//use Yilianyun\Config\YlyConfig;
//use Yilianyun\Oauth\YlyOauthClient;
//use Yilianyun\Api\PrinterService;
//use Yilianyun\Api\PrintService;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\Printer;
use Xpyun\model\PrintRequest;
use Xpyun\service\PrintService;
use Xpyun\util\NoteFormatter;
use app\admin\model\Yee;
use app\admin\model\Yeemicro;
use app\admin\model\system_config\Storeset;
use app\admin\model\goods_manage\Goods;
use app\admin\model\gas\Gasset;
use app\admin\model\gas\Gasgun;
use app\common\model\StoreConfig;
use app\admin\model\Oilorder;
use app\admin\model\station\Station;
use app\admin\model\Oilprice;
/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    public function _initialize()
    {
        parent::_initialize();

//      if (!Config::get('fastadmin.usercenter')) {
//          $this->error(__('User center already closed'));
//      }

    }
    /**
     * 首页
     *
     */
    public function index(Request $request)
    {
    	$store_no = $this->request->post('store_no');
    	$data['banner_list'] = \app\admin\model\system_config\Banner::where('store_no', $store_no)->where('position', 1)->select();
    	$data['buttom_list'] = \app\admin\model\system_config\Banner::where('store_no', $store_no)->where('position', 2)->select();
    	$data['oil_list'] = \app\admin\model\gas\Gasset::where('store_no', $store_no)->select();
    	$data['store_detail'] = \app\admin\model\system_config\Storeset::where('store_no', $store_no)->find();
        $this->success('请求成功',$data);
    }
    
    /**
     * 油枪
     *
     */
    public function getoil()
    {
    	$store_no = $this->request->post('store_no');
    	$data['oil_list'] = \app\admin\model\gas\Gasset::where('store_no', $store_no)->select();
    	$data['store_detail'] = \app\admin\model\system_config\Storeset::where('store_no', $store_no)->find();
    	foreach ($data['oil_list'] as $index => $item) {
    		$item['gun'] = \app\admin\model\gas\Gasgun::where('gas_id', $item['id'])->select();
    	}
        $this->success('请求成功',$data);
    }
    
    /**
     * 活动
     *
     */
    public function getactivity()
    {
    	$store_no = $this->request->post('store_no');
    	$data = \app\admin\model\system_config\Activity::where('store_no', $store_no)->select();

        $this->success('请求成功',$data);
    }
    
        /**
     * 商品分类
     *
     */
    public function getcats()
    {
    	$store_no = $this->request->post('store_no');
    	$data = \app\admin\model\goods_manage\Cats::where('store_no', $store_no)->select();

        $this->success('请求成功',$data);
    }
    
           /**
     * 商品信息
     *
     */
    public function getgoodslist()
    {
    	$user_id = $this->request->post('user_id');
    	$store_no = $this->request->post('store_no');
    	$cat_id = $this->request->post('cat_id');
    	$data = \app\admin\model\goods_manage\Goods::where('store_no', $store_no)->where('cat_id', $cat_id)->select();
        foreach ($data as $index => $item) {
        	$item['cart_num'] = 0;
        	if($user_id)
        	{
        		$cartinfo = Cart::where('user_id', $user_id)->where('goods_id', $item['id'])->find();
        		$item['cart_num'] = $cartinfo['num'];
        	}
    		
    	}
        $this->success('请求成功',$data);
    }
    
           /**
     * 商品信息
     *
     */
    public function getgoodsdetail()
    {
    	$store_no = $this->request->post('store_no');
    	$goods_id = $this->request->post('goods_id');
    	$data = \app\admin\model\goods_manage\Goods::where('store_no', $store_no)->where('id', $goods_id)->find();

        $this->success('请求成功',$data);
    }
    
            /**
     * 获取支付后广告
     *
     */
    public function getpayad()
    {
    	$store_no = $this->request->post('store_no');

    	$data = Payad::where('store_no', $store_no)->orderRaw('rand()')->find();

        $this->success('请求成功',$data);
    }
    
           /**
     * 提交订单
     *
     */
    public function submit()
    {
//  	$user = $this->auth->getUser();
        $store_no = $this->request->post('store_no');
    	$type = $this->request->post('type');//2加油  3 商品
    	$goods_id = $this->request->post('goods_id');
    	$num = $this->request->post('num');//商品商量
    	$total_amount = $this->request->post('total_amount');//订单总额
    	$pay_type = $this->request->post('pay_type');//订单总额
    	$gas_id = $this->request->post('gas_id');
    	$gas_gun_id = $this->request->post('gas_gun_id');
//  	$store_no = 1;
//  	$type = 2;//2加油  3 商品
//  	$goods_id = 1;
//  	$num = 1;//商品商量
//  	$total_amount = 100;//订单总额
//  	$pay_type = 1;//订单总额
//  	$money = 200;
//  	$gas_id= 1;
//  	$gas_gun_id= 1;
    	if($pay_type == 1&&$total_amount > $user->money)$this->error('余额不足');
    	$osn = date('YmdHis') . rand(10000000,99999999);
    	if($type == 2)
    	{
    		$oil = \app\admin\model\gas\Gasset::where('id',$gas_id)->find();
    		if(!$oil)$this->error('油号不存在');
    		$paramgas['agent_id']=1;
	        $paramgas['store_no']=1;
	        $paramgas['user_id']=$user->id;
	        $paramgas['order_no']=$osn;
	        $paramgas['total_price']=$total_amount;
	        $paramgas['total_pay_price']=$total_amount;
	        $paramgas['discount_price']=0;
	        $paramgas['is_pay']=2;
	        $paramgas['pay_type']=$pay_type;
	        $paramgas['pay_time']=time();
	        $paramgas['source_type']=1;
    		$resultgas = \app\admin\model\exchange\Ordergas::create($paramgas);
    		if($resultgas)
    		{
    			$num = round($total_amount/$oil['price'],2);
    			//订单详情
    			$paraminfo['agent_id']=1;
		        $paraminfo['store_no']=1;
		        $paraminfo['order_id']=$resultgas['id'];
		        $paraminfo['gas_gun_id']=$gas_gun_id;
		        $paraminfo['num']=$num;
		        $paraminfo['unit_price']=$oil['price'];
		        $paraminfo['total_price']=$total_amount;
		        $paraminfo['unit']=$oil['unit'];

	    		$resultinfo = \app\admin\model\exchange\OrderGasInfo::create($paraminfo);
	    		//录入总订单
	    		$params['agent_id']=1;
		        $params['store_no']=1;
		        $params['user_id']=$user->id;
		        $params['order_no']=$osn;
		        $params['total_price']=$total_amount;
		        $params['total_pay_price']=$total_amount;
		        $params['discount_price']=0;
		        $params['is_pay']=2;
		        $params['pay_type']=$pay_type;
		        $params['type']=$type;
		        $params['source_type']=1;
		        $params['pay_time']=time();
		    
		    	$result = \app\admin\model\exchange\Order::create($params);
		    	$before = $user->money;
		    	$money = $user->money - $total_amount;
		    	$user->money = $money;
                $user->save();
                $memo = '油品下单';
                //写入日志
                $resultmo = \app\common\model\MoneyLog::create(['user_id' => $user->id, 'money' => $total_amount, 'before' => $before, 'after' => $money, 'memo' => $memo]);
		    	
		    	$this->success('支付成功');
    		}
    		
    		$this->error('支付失败');
    	}
    	if($type == 3)
    	{
    		$good = \app\admin\model\goods_manage\Goods::where('id',$goods_id)->find();
    		if(!$good)$this->error('商品不存在');
    		$paramgood['agent_id']=1;
	        $paramgood['store_no']=1;
	        $paramgood['user_id']=$user->id;
	        $paramgood['order_no']=$osn;
	        $paramgood['total_price']=$total_amount;
	        $paramgood['total_pay_price']=$total_amount;
	        $paramgood['discount_price']=0;
	        $paramgood['is_pay']=2;
	        $paramgood['pay_type']=$pay_type;
	        $paramgood['pay_time']=time();
	        $paramgood['source_type']=1;
    		$resultgood = \app\admin\model\exchange\Ordergoods::create($paramgood);
    		if($resultgood)
    		{
    	
    			//订单详情
    			$paraminfo['agent_id']=1;
		        $paraminfo['store_no']=1;
		        $paraminfo['order_id']=$resultgood['id'];
		        $paraminfo['goods_id']=$goods_id;
		        $paraminfo['num']=$num;
		        $paraminfo['unit_price']=$good['price'];
		        $paraminfo['total_price']=$total_amount;
		        $paraminfo['goods_sku']=$good['sku'];

	    		$resultinfo = \app\admin\model\exchange\OrderGoodsInfo::create($paraminfo);
	    		//录入总订单
	    		$params['agent_id']=1;
		        $params['store_no']=1;
		        $params['user_id']=$user->id;
		        $params['order_no']=$osn;
		        $params['total_price']=$total_amount;
		        $params['total_pay_price']=$total_amount;
		        $params['discount_price']=0;
		        $params['is_pay']=2;
		        $params['pay_type']=$pay_type;
		        $params['type']=$type;
		        $params['source_type']=1;
		        $params['pay_time']=time();
		    
		    	$result = \app\admin\model\exchange\Order::create($params);
		    	$before = $user->money;
		    	$money = $user->money - $total_amount;
		    	$user->money = $money;
                $user->save();
                $memo = '商品下单';
                //写入日志
                $resultmo = \app\common\model\MoneyLog::create(['user_id' => $user->id, 'money' => $total_amount, 'before' => $before, 'after' => $money, 'memo' => $memo]);
		    	
		    	$this->success('支付成功');
    		}
    		
    		$this->error('支付失败');
    	}
    	$this->error('支付失败');
    }
    

     public function payment()
    {
        /*商户私钥*/
        $private_key ="MIIEugIBADANBgkqhkiG9w0BAQEFAASCBKQwggSgAgEAAoIBAQCQMqL/T97RhAophQNRzBwE+vU+59PzfkEzyLZwMaQTduHvdTl4fg6KZ6ATFUgECI2JLpZq3cyjVYSlM9H20bRpZSaoYmsYyNibpf2lg+bMg9G+bS6elHvFn0ZJ+aU40wyWqPjtdLB9JYLDbLVsb6SzHegWovWeWD7vUqCbPhDK24V///baX2zV4609kfa1iBGbynF/0nggHw3leeUW9F8E8twSEF15ObE8ShywOMvi578kv9PUNmSiq8gfc/t8dWVOzi4mbDje49MhxMbuopGv1kcvHBrThTeqQ2plhQSs63AbwLpe4WsZbcNvG9zpjuci8bK1+Zb/3DnkmT4zEu6FAgMBAAECggEAHsQfEPhaoztX67nslmRFSi69atmN2HMEuGbHvjJpPpnr5OqPA41pztADUG8G+Y1VnYJqJ40BX4wcjB79Wnst0hr53414KkaYKMWG0+zLrrElbErhWoZ1zhmIprn0LaaiFfchfZCbI2iAeO/V2bgMXQcxgLruSwWrD+cCS303mgBgW7tWsqlfplLvtWqJBWyA4Y8ObV/RUuLjr38Q8nCGZ81ep+De0euDkV4JQ/tg7uQEvEAOwpB6EEBwYt8GZVwcq8SWfP1cOw0Q7hkvn+rHvnXa2MHg8pdQHOfigvHr4Z5udkSiM885Pbjyh6H+UldtKFx2pW9EoD4t37CMwjeJtQKBgQDMWc00sfln9lRUBarV0D7fL6Z8/kueyBaTXFrzauHGwqK9KvB9ADmqFuBxZij8fJBkQyQtgNgbutTqgo0BJgTB2Q5lH097SBUdrTUrJdo3+rKY4/fbQBU7zF9oQ2p+dyFHmW/zjjWALnQYchd1lsZGkrSg2qPto/PRttkES/jrywKBgQC0pLrjcQ+6XZAUie+wSML+f/zGvxw1821Tn8poe0FIaX7/vPhRo028eF+R4Kav/yiVxeTAzk1D5OtN0Q3XO/nIY6f68WbdjBeFFSyovpPi1GX8kSys5wIo79nNnF/cEIJMTnvmyn51RaH8jtSVhshqqzHdesezXTYV3lwg4Urk7wKBgFqKS0ZWuIdcd76GiEuVqdWfOifVT9H5Gy+NUurY51H2OL6RwN3RdLssyaLUvcIoup0BtozGsnmOzPlegHUK0D7HGf6p4cBgjqKIdK86ZTY6SFk/YDjvarkE8xyyCgQgaklb7WM/FetGKcAPBN/fvtfT9l3yoYEQDF5Vok+qDY8DAn80N2nOVOA2/tSnGzgtvNqgtl5bFOMStUrk4Uug5//27ofHZNhiwNG3qRP3FvkX5qnUoV9+XCP5fDKIS+W0UaHiSuxDnYQehmBGF9jQ7kXRS5Qvbcd8M0psiuhqhsku05bWd9lY3S+wtnAckSziDBPiwZmoa9VOA6Oerqfy2SzNAoGAETFFK7YKO6+fGNJv5M5KJuZsOGkqgmfkJhAOnC2wLPDMMFDXnWG+oPcI6bosyvM+I8FDqwE3VcbmFlEJPnC4hQvwK3JjAju6FGhDgoB98rihcaUlsJfoTvrSmkLAmQOH8DW+a0UVbcCMp7TtWgpC8UMT0adAb/4ngQhjYuED4pI=";

        $request = new YopRequest("app_10088909942", $private_key);

        //加入请求参数
        $request->addParam("parentMerchantNo",'10088909942');
        $request->addParam("merchantNo",'10088970121');
        $request->addParam("orderId",'123123124141142');
        $request->addParam("orderAmount",11);
        $request->addParam("expiredTime",'');
        $request->addParam("notifyUrl",'');
        $request->addParam("memo",'');
        $request->addParam("goodsName",'');
        $request->addParam("fundProcessType",'');
        $request->addParam("payWay",'MINI_PROGRAM');
        $request->addParam("channel", 'WECHAT');
        $request->addParam("scene", 'OFFLINE');
        $request->addParam("appId", 'wx36cbd21e9ad4ea77');
        $request->addParam("userId", 'ovr9i4yBLu5mI--pgxqgOvuLsNlc');
        $request->addParam("userIp", '123.123.123.123');
        $request->addParam("intNum", 56);
        $request->addParam("bigDecimalNum", 1.2);
        $request->addParam("longNum", 789);
//      //提交Post请求
        $response = YopRsaClient::post("/rest/v1.0/aggpay/pre-pay", $request);

    	$this->error($response);
    }
    public function sandpayment()
    {
        
        $request = new HmPayClient();

        $url = $request->gatewayUrl;

        $appId = '552021071325659';
        $subAppId = $request->subAppId;
        $method = "trade.percreate";
        $format = $request->format;
        $charset = $request->charset;
        $signType = $request->signType;
        $version = $request->apiVersion;
        $timestamp = date("Y-m-d h:i:s");
        $nonce = $request->getRandStr(8);
        $privateKey = $request->rsaPrivateKey;
        //支付方式
        $payWay = "WECHAT";
        $createIp = "127.0.0.1";//生产环境使用真实ip
        $createTime = date("YmdHis");
        $expireTime = date("YmdHis", strtotime("+10 minute"));//过期时间
        $totalAmount = 1.00;
        $outOrderNo = $request->buildOrderNo();
        //商品详情 -- 按实际填写 或不填不上送
        $goodsDetail1 = array();
        $goodsDetail1['goods_id'] = 'a01';
        $goodsDetail1['goods_name'] = 'a1';
        $goodsDetail1['quantity'] = '1';
        $goodsDetail1['price'] = '0.01';

        $goodsDetail2 = array();
        $goodsDetail2['goods_id'] = 'a02';
        $goodsDetail2['goods_name'] = 'a2';
        $goodsDetail2['quantity'] = '1';
        $goodsDetail2['price'] = '0.99';
        $goodsDetail = array($goodsDetail1, $goodsDetail2);
        //订单详情
        $body = "无人超市";
        //商户交易门店
        $storeId = "100001";
        //终端信息
        $deviceInfo = array();
        $deviceInfo['longitude'] = '121.506377';
        $deviceInfo['latitude'] = '31.245105';

        $notifyUrl = null;

        $bizContent = $request->tradePrecreate($payWay, $createIp, $createTime, $expireTime, $totalAmount, $outOrderNo, $goodsDetail, $body, $storeId, $notifyUrl);
        
        $response = $request->execute($url, $request->request($appId, $subAppId, $method, $format, $charset, $signType, $timestamp, $nonce, $version, $bizContent, $privateKey));
        
        $jsonResp = json_decode($response, JSON_UNESCAPED_UNICODE);
        $this->error($jsonResp);
        try {
            $request->checkResponseSign($jsonResp, $request->platRsaPublicKey, $signType);
        } catch (Exception $e) {
            error_log($e->getMessage());
            //todo 验签异常或失败
        }
    }
    public function notify()
    {
    	$response = $this->request->post('response');
        $customerIdentification = $this->request->post('customerIdentification');
         /*商户私钥*/
        $private_key ="MIIEugIBADANBgkqhkiG9w0BAQEFAASCBKQwggSgAgEAAoIBAQCQMqL/T97RhAophQNRzBwE+vU+59PzfkEzyLZwMaQTduHvdTl4fg6KZ6ATFUgECI2JLpZq3cyjVYSlM9H20bRpZSaoYmsYyNibpf2lg+bMg9G+bS6elHvFn0ZJ+aU40wyWqPjtdLB9JYLDbLVsb6SzHegWovWeWD7vUqCbPhDK24V///baX2zV4609kfa1iBGbynF/0nggHw3leeUW9F8E8twSEF15ObE8ShywOMvi578kv9PUNmSiq8gfc/t8dWVOzi4mbDje49MhxMbuopGv1kcvHBrThTeqQ2plhQSs63AbwLpe4WsZbcNvG9zpjuci8bK1+Zb/3DnkmT4zEu6FAgMBAAECggEAHsQfEPhaoztX67nslmRFSi69atmN2HMEuGbHvjJpPpnr5OqPA41pztADUG8G+Y1VnYJqJ40BX4wcjB79Wnst0hr53414KkaYKMWG0+zLrrElbErhWoZ1zhmIprn0LaaiFfchfZCbI2iAeO/V2bgMXQcxgLruSwWrD+cCS303mgBgW7tWsqlfplLvtWqJBWyA4Y8ObV/RUuLjr38Q8nCGZ81ep+De0euDkV4JQ/tg7uQEvEAOwpB6EEBwYt8GZVwcq8SWfP1cOw0Q7hkvn+rHvnXa2MHg8pdQHOfigvHr4Z5udkSiM885Pbjyh6H+UldtKFx2pW9EoD4t37CMwjeJtQKBgQDMWc00sfln9lRUBarV0D7fL6Z8/kueyBaTXFrzauHGwqK9KvB9ADmqFuBxZij8fJ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W5ZzZJLQ6tZDojBK4GZTAGhnn3bg5bBsBlw2+FLkCQBuDsJVsFPiGh/b6K/+zGTvWyUcu+LUj2MejYQELDO3i2vQXVDk7lVi2/TcUYefvIcssnzsfCfjaorxsuwIDAQAB";
        $decryptresponse = YopSignUtils::decrypt($response,$private_key,$yopPublicKey);

        $decrypt = json_decode($decryptresponse);
         $response = json_encode($response);
        YeeRepose::create([
            'response' => $response,
            'customer' => $customerIdentification,
            'dec' =>$decryptresponse,
            'type' =>1,
        ]);
        
        if($decrypt->applicationStatus)
	    {
	    	if($decrypt->applicationStatus == 'AGREEMENT_SIGNING')$para['agreementSignUrl'] = $decrypt->agreementSignUrl;
	    	if($decrypt->applicationStatus == 'COMPLETED')$para['merchantNo'] = $decrypt->merchantNo;
	    	$para['applicationStatus'] = $decrypt->applicationStatus;
	    	Yee::where('requestNo', $decrypt->requestNo)->update($para);
	    }
	    
        echo 'OK';
    }
    
    public function micronotify()
    {
    	$response = $this->request->post('response');
        $customerIdentification = $this->request->post('customerIdentification');
         /*商户私钥*/
        $private_key ="MIIEugIBADANBgkqhkiG9w0BAQEFAASCBKQwggSgAgEAAoIBAQCQMqL/T97RhAophQNRzBwE+vU+59PzfkEzyLZwMaQTduHvdTl4fg6KZ6ATFUgECI2JLpZq3cyjVYSlM9H20bRpZSaoYmsYyNibpf2lg+bMg9G+bS6elHvFn0ZJ+aU40wyWqPjtdLB9JYLDbLVsb6SzHegWovWeWD7vUqCbPhDK24V///baX2zV4609kfa1iBGbynF/0nggHw3leeUW9F8E8twSEF15ObE8ShywOMvi578kv9PUNmSiq8gfc/t8dWVOzi4mbDje49MhxMbuopGv1kcvHBrThTeqQ2plhQSs63AbwLpe4WsZbcNvG9zpjuci8bK1+Zb/3DnkmT4zEu6FAgMBAAECggEAHsQfEPhaoztX67nslmRFSi69atmN2HMEuGbHvjJpPpnr5OqPA41pztADUG8G+Y1VnYJqJ40BX4wcjB79Wnst0hr53414KkaYKMWG0+zLrrElbErhWoZ1zhm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Ab/4ngQhjYuED4pI=";
        $yopPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6p0XWjscY+gsyqKRhw9MeLsEmhFdBRhT2emOck/F1Omw38ZWhJxh9kDfs5HzFJMrVozgU+SJFDONxs8UB0wMILKRmqfLcfClG9MyCNuJkkfm0HFQv1hRGdOvZPXj3Bckuwa7FrEXBRYUhK7vJ40afumspthmse6bs6mZxNn/mALZ2X07uznOrrc2rk41Y2HftduxZw6T4EmtWuN2x4CZ8gwSyPAW5ZzZJLQ6tZDojBK4GZTAGhnn3bg5bBsBlw2+FLkCQBuDsJVsFPiGh/b6K/+zGTvWyUcu+LUj2MejYQELDO3i2vQXVDk7lVi2/TcUYefvIcssnzsfCfjaorxsuwIDAQAB";
        $decryptresponse = YopSignUtils::decrypt($response,$private_key,$yopPublicKey);

        $decrypt = json_decode($decryptresponse);
         $response = json_encode($response);
        YeeRepose::create([
            'response' => $response,
            'customer' => $customerIdentification,
            'dec' =>$decryptresponse,
            'type' =>6,
        ]);
        
        if($decrypt->applicationStatus)
	    {
	    	if($decrypt->applicationStatus == 'AGREEMENT_SIGNING')$para['agreementSignUrl'] = $decrypt->agreementSignUrl;
	    	if($decrypt->applicationStatus == 'COMPLETED')$para['merchantNo'] = $decrypt->merchantNo;
	    	$para['applicationStatus'] = $decrypt->applicationStatus;
	    	Yeemicro::where('requestNo', $decrypt->requestNo)->update($para);
	    }
	    
        echo 'OK';
    }
    
    public function yeenotify()
    {
    	$response = $this->request->post('response');
        $customerIdentification = $this->request->post('customerIdentification');
         /*商户私钥*/
        $private_key ="MIIEugIBADANBgkqhkiG9w0BAQEFAASCBKQwggSgAgEAAoIBAQCQMqL/T97RhAophQNRzBwE+vU+59PzfkEzyLZwMaQTduHvdTl4fg6KZ6ATFUgECI2JLpZq3cyjVYSlM9H20bRpZSaoYmsYyNibpf2lg+bMg9G+bS6elHvFn0ZJ+aU40wyWqPjtdLB9JYLDbLVsb6SzHegWovWeW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uug5//27ofHZNhiwNG3qRP3FvkX5qnUoV9+XCP5fDKIS+W0UaHiSuxDnYQehmBGF9jQ7kXRS5Qvbcd8M0psiuhqhsku05bWd9lY3S+wtnAckSziDBPiwZmoa9VOA6Oerqfy2SzNAoGAETFFK7YKO6+fGNJv5M5KJuZsOGkqgmfkJhAOnC2wLPDMMFDXnWG+oPcI6bosyvM+I8FDqwE3VcbmFlEJPnC4hQvwK3JjAju6FGhDgoB98rihcaUlsJfoTvrSmkLAmQOH8DW+a0UVbcCMp7TtWgpC8UMT0adAb/4ngQhjYuED4pI=";
        $yopPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6p0XWjscY+gsyqKRhw9MeLsEmhFdBRhT2emOck/F1Omw38ZWhJxh9kDfs5HzFJMrVozgU+SJFDONxs8UB0wMILKRmqfLcfClG9MyCNuJkkfm0HFQv1hRGdOvZPXj3Bckuwa7FrEXBRYUhK7vJ40afumspthmse6bs6mZxNn/mALZ2X07uznOrrc2rk41Y2HftduxZw6T4EmtWuN2x4CZ8gwSyPAW5ZzZJLQ6tZDojBK4GZTAGhnn3bg5bBsBlw2+FLkCQBuDsJVsFPiGh/b6K/+zGTvWyUcu+LUj2MejYQELDO3i2vQXVDk7lVi2/TcUYefvIcssnzsfCfjaorxsuwIDAQAB";
        $decryptresponse = YopSignUtils::decrypt($response,$private_key,$yopPublicKey);

        $decrypt = json_decode($decryptresponse);
         $response = json_encode($response);
             YeeRepose::create([
            'response' => $response,
            'customer' => $customerIdentification,
            'dec' =>$decryptresponse,
            'type' =>2,
        ]);

        if($decrypt->status == 'SUCCESS')
	    {
	    	$order = Order::where('order_no', $decrypt->orderId)->find();
	    	
        	if($order&&$order['is_pay'] == 0)
        	{
        		Order::where('order_no', $decrypt->orderId)->update(['is_pay' => 2]);
        		if($order['type'] == 1)
        		{
        			Orderrecharge::where('order_no', $decrypt->orderId)->update(['is_pay'=>2]);
        			UserDetail::where('id',$order['user_id'])->setInc('money', $order['total_pay_price']+$order['gift_amount']);
        		}
        		if($order['type'] == 2)Ordergas::where('order_no', $decrypt->orderId)->update(['is_pay'=>2]);
        		if($order['type'] == 3)Ordergoods::where('order_no', $decrypt->orderId)->update(['is_pay'=>2]);
        		if($order['type'] == 4){
        			Ordergas::where('order_no', $decrypt->orderId)->update(['is_pay'=>2]);
        			Ordergoods::where('order_no', $decrypt->orderId)->update(['is_pay'=>2]);
        		}
        	}
	    }
        
   
        echo 'OK';
    }
    
    public function sandnotify()
    {

    	$response = $this->request->request();
    	$total_amount = $this->request->post('total_amount');
    	$merOrderNum= $this->request->post('merOrderNum');
        $orderNumber= $this->request->post('orderNumber');
        $payType= $this->request->post('payType');
    	$jsonresponse = json_encode($response);

    	if(empty($payStatus))return 'fail';
    	
    	  YeeRepose::create([
            'response' => $jsonresponse,
            'customer' => 11,
            'dec' =>12,
            'type' =>4,
        ]);
//      $is_pay=0;
//      if($payStatus == '成功')$is_pay=2;
//      if($payStatus == '退款成功')$is_pay=1;
//      if($is_pay >0)
//      {
//      	$order = Order::where('order_no', $out_order_no)->find();
//      	if($order&&$order['is_pay'] ==0)
//      	{
			if($response['payStatus'] == '成功')
		    {
		    	$type = 3;
		    	if($payType == "03")$type = 1;
		    	if($payType == "04")$type = 2;
        		Order::where('order_no', $response['merOrderNum'])->update(['is_pay'=>2,'bank_no'=>$orderNumber,'pay_type'=>$type]);
        		Ordergas::where('order_no', $response['merOrderNum'])->update(['is_pay'=>2,'bank_no'=>$orderNumber,'pay_type'=>$type]);
        		Ordergoods::where('order_no', $response['merOrderNum'])->update(['is_pay'=>2,'bank_no'=>$orderNumber,'pay_type'=>$type]);
        		
        	}
        	
        	
        	if($response['payStatus'] == '退款成功')
		    {
        		Order::where('order_no', $response['merOrderNum'])->update(['is_pay'=>1,'status'=> 2]);
        		Ordergas::where('order_no', $response['merOrderNum'])->update(['is_pay'=>1,'status'=> 2]);
        		Ordergoods::where('order_no', $response['merOrderNum'])->update(['is_pay'=>1,'status'=> 2]);
        		
        	}
        	
        	
        	
//      	}
//      	
//      }
        
    
        echo 'OK';
    }
    public function sandscannotify()
    {

    	$response = $this->request->request();
//  	$trade_status = $this->request->post('trade_status');
//  	$out_order_no= $this->request->post('out_order_no');
    	 $jsonresponse = json_encode($response);
    	  YeeRepose::create([
            'response' => $jsonresponse,
            'customer' => 11,
            'dec' =>$response['out_order_no'],
            'type' =>3,
        ]);
       
//      $customerIdentification = $this->request->post('customerIdentification');
//       /*商户私钥*/
//      $private_key ="MIIEugIBADANBgkqhkiG9w0BAQEFAASCBKQwggSgAgEAAoIBAQCQMqL/T97RhAophQNRzBwE+vU+59PzfkEzyLZwMaQTduHvdTl4fg6KZ6ATFUgECI2JLpZq3cyjVYSlM9H20bRpZSaoYmsYyNibpf2lg+bMg9G+bS6elHvFn0ZJ+aU40wyWqPjtdLB9JYLDbLVsb6SzHegWovWeWD7vUqCbPhDK24V///baX2zV4609kfa1iBGbynF/0nggHw3leeUW9F8E8twSEF15ObE8ShywOMvi578kv9PUNmSiq8gfc/t8dWVOzi4mbDje49MhxMbuopGv1kcvHBrThTeqQ2plhQSs63AbwLpe4WsZbcNvG9zpjuci8bK1+Zb/3DnkmT4zEu6FAgMBAAECggEAHsQfEPhaoztX67nslmRFSi69atmN2HMEuGbHvjJpPpnr5OqPA41pztADUG8G+Y1VnYJqJ40BX4wcjB79Wnst0hr53414KkaYKMWG0+zLrrElbErhWoZ1zhmIprn0LaaiFfchfZCbI2iAeO/V2bgMXQcxgLruSwWrD+cCS303mgBgW7tWsqlfplLvtWqJBWyA4Y8ObV/RUuLjr38Q8nCGZ81ep+De0euDkV4JQ/tg7uQEvEAOwpB6EEBwYt8GZVwcq8SWfP1cOw0Q7hkvn+rHvnXa2MHg8pdQHOfigvHr4Z5udkSiM885Pbjyh6H+UldtKFx2pW9EoD4t37CMwjeJtQKBgQDMWc00sfln9lRUBarV0D7fL6Z8/kueyBaTXFrzauHGwqK9KvB9ADmqFuBxZij8fJBkQyQtgNgbutT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tZDojBK4GZTAGhnn3bg5bBsBlw2+FLkCQBuDsJVsFPiGh/b6K/+zGTvWyUcu+LUj2MejYQELDO3i2vQXVDk7lVi2/TcUYefvIcssnzsfCfjaorxsuwIDAQAB";
//      $decryptresponse = YopSignUtils::decrypt($response,$private_key,$yopPublicKey);
        if($response['trade_status'] == 'SUCCESS')
        {
        	$order = Order::where('order_no', $response['out_order_no'])->find();
        	if($order&&$order['is_pay'] ==0)
        	{
        		Order::where('order_no', $response['out_order_no'])->update(['is_pay'=>2,'ordernum'=>$response['plat_trx_no'],'bank_no'=>$response['bank_order_no']]);
        		if($order['type'] == 1)
        		{
        			Orderrecharge::where('order_no', $response['out_order_no'])->update(['is_pay'=>2,'ordernum'=>$response['plat_trx_no'],'bank_no'=>$response['bank_order_no']]);
        			UserDetail::where('id',$order['user_id'])->setInc('money', $order['total_pay_price']+$order['gift_amount']);
        			
        		}
        		if($order['type'] == 2)Ordergas::where('order_no', $response['out_order_no'])->update(['is_pay'=>2,'ordernum'=>$response['plat_trx_no'],'bank_no'=>$response['bank_order_no']]);
        		if($order['type'] == 3)Ordergoods::where('order_no', $response['out_order_no'])->update(['is_pay'=>2,'ordernum'=>$response['plat_trx_no'],'bank_no'=>$response['bank_order_no']]);
        		if($order['type'] == 4){
        			Ordergas::where('order_no', $response['out_order_no'])->update(['is_pay'=>2,'ordernum'=>$response['plat_trx_no'],'bank_no'=>$response['bank_order_no']]);
        			Ordergoods::where('order_no', $response['out_order_no'])->update(['is_pay'=>2,'ordernum'=>$response['plat_trx_no'],'bank_no'=>$response['bank_order_no']]);
        		}
        	}
        	
        }
        
    
        echo 'OK';
    }
    public function ceshiprint()
    {
    	$config = new YlyConfig('1056778478', '52dc0ea2e501aae12e3fbd59dc59c631');

		$client = new YlyOauthClient($config);
		$token = $client->getToken();   //若是开放型应用请传授权码code
		
		$printer = new PrinterService($token->access_token, $config);
		$data = $printer->addPrinter('4004818534', '938173768207', '机器昵称也可不填', 'gprs卡号没有可不填');
		
		$print = new PrintService($token->access_token, $config);
//		$data = $print->index('4004818534','打印内容排版可看Demo下的callback.php','你的系统内部id自定义32位以内');
		/**文本接口开始**/
//		$print = new PrintService($access_token, $config);
		//58mm排版 排版指令详情请看 http://doc2.10ss.net/332006
		$content = "<FS2><center>**#1 美团**</center></FS2>";
		$content .= str_repeat('.', 32);
		$content .= "<FS2><center>--在线支付--</center></FS2>";
		$content .= "<FS><center>张周兄弟烧烤</center></FS>";
		$content .= "订单时间:". date("Y-m-d H:i") . "\n";
		$content .= "订单编号:40807050607030\n";
		$content .= str_repeat('*', 14) . "商品" . str_repeat("*", 14);
		$content .= "<table>";
		$content .= "<tr><td>烤土豆(超级辣)</td><td>x3</td><td>5.96</td></tr>";
		$content .= "<tr><td>烤豆干(超级辣)</td><td>x2</td><td>3.88</td></tr>";
		$content .= "<tr><td>烤鸡翅(超级辣)</td><td>x3</td><td>17.96</td></tr>";
		$content .= "<tr><td>烤排骨(香辣)</td><td>x3</td><td>12.44</td></tr>";
		$content .= "<tr><td>烤韭菜(超级辣)</td><td>x3</td><td>8.96</td></tr>";
		$content .= "</table>";
		$content .= str_repeat('.', 32);
		$content .= "<QR>www.baidu.com</QR>";
		$content .= "小计:￥82\n";
		$content .= "折扣:￥４ \n";
		$content .= str_repeat('*', 32);
		$content .= "订单总价:￥78 \n";
		$content .= "<FS2><center>**#1 完**</center></FS2>";
		$data = $print->index('4004818534', $content,'你的系统内部id自定义32位以内');
//		try{
//		    var_dump($print->index('4004818534', $content));
//		}catch (Exception $e) {
//		    echo $e->getMessage();
//		}
		var_dump($data);
    }
    public function eightprint()
    {
    	        /**
         * <BR>：换行符（同一行有闭合标签(如 </C>)则应放到闭合标签前面, 连续两个换行符<BR><BR>可以表示加一空行）
         *  <L></L>：左对齐
         *  <C></C>：居中对齐
         *  <R></R>：右对齐
         *  注意：同一行内容不能使用多种对齐方式，可通过补空格方式自定义对齐样式。
         *       58mm的机器，一行打印16个汉字，32个字母
         *       80mm的机器，一行打印24个汉字，48个字母
         *
         *  <N></N>：字体正常大小
         *  <HB></HB>：字体变高一倍
         *  <WB></WB>：字体变宽一倍
         *  <B></B>：字体放大一倍
         *  <CB></CB>：字体放大一倍居中
         *  <HB2></HB2>：字体变高二倍
         *  <WB2></WB2>：字体变宽二倍
         *  <B2></B2>：字体放大二倍
         *  <BOLD></BOLD>：字体加粗
         *  <IMG></IMG>：打印LOGO图片，需登录开放平台在【打印机管理=》设备管理】下通过设置LOGO功能进行上传。此处直接写入
         *             空标签, 如 <IMG></IMG> 即可, 具体可参考样例。
         *             图片宽度设置：可以通过 <IMG> 标签名称自定义，如 <IMG60> 表示宽度为60，相应的闭合标签 </IMG>
         *             不需要指定高度。<IMG> 标签不指定宽度默认为40，最小值为20，最大值为100
         *  <QR></QR>：二维码（标签内容是二维码值, 最大不能超过256个字符, 单个订单最多只能打印一个二维码）。
         *             二维码宽度设置：可以通过 <QR> 标签名称自定义，如 <QR180> 表示宽度为180，相应的闭合标签 </QR>
         *             不需要指定宽度。<QR> 标签不指定宽度默认为110，最小值为90，最大值为180
         *  <BARCODE></BARCODE>：条形码（标签内容是条形码值）
         */
        $store_no = 1;
        $osn = "2023020915430674623773";
        $storeinfo = Storeset::where('store_no',$store_no)->find();
        $order = Order::where('order_no', $osn)->find();
        $ordergas = Ordergas::where('order_no', $osn)->find();
        $ordergoods = Ordergoods::where('order_no', $osn)->find();
        $ordergasinfo = OrderGasInfo::where('order_id', $ordergas['id'])->select();
        $ordergoodsinfo = OrderGoodsInfo::where('order_id', $ordergoods['id'])->select();
        
        $printContent = "";

        $printContent = $printContent . "<C>" . "<B>".$storeinfo['store_name']."</B>" . "<BR></C>";
        $printContent = $printContent . "<BR>";
        if($ordergoodsinfo)
		{
	        $printContent = $printContent . "商品" . str_repeat(" ",15) . "数量" . str_repeat(" ", 2) . "单价" . str_repeat(" ", 2)
	            . "<BR>";
	        $printContent = $printContent . str_repeat("-", NoteFormatter::ROW_MAX_CHAR_LEN) . "<BR>";
	        foreach ($ordergoodsinfo as $in => $it) {	
	        	$goodinfo = Goods::where('id', $it['goods_id'])->find();
	            $printContent = $printContent . NoteFormatter::formatPrintOrderItem($goodinfo['goods_name'], $it['num'], $it['unit_price']);
	        }
	        $printContent = $printContent . str_repeat("-", NoteFormatter::ROW_MAX_CHAR_LEN) . "<BR>";
        }	
        if($ordergasinfo)
		{
	        $printContent = $printContent . "油品" . str_repeat(" ",15) . "数量" . str_repeat(" ", 2) . "单价" . str_repeat(" ", 2)
	            . "<BR>";
	        $printContent = $printContent . str_repeat("-", NoteFormatter::ROW_MAX_CHAR_LEN) . "<BR>";
	        foreach ($ordergasinfo as $k => $v) {
	        	$guninfo = Gasgun::where('id', $v['gas_gun_id'])->find();
				$gasinfo = Gasset::where('id', $guninfo['gas_id'])->find();
	            $printContent = $printContent . NoteFormatter::formatPrintOrderItem($gasinfo['gas_name'], $v['num'], $v['unit_price']);
	        }
	        $printContent = $printContent . str_repeat("-", NoteFormatter::ROW_MAX_CHAR_LEN) . "<BR>";
        }
        	
        $printContent = $printContent . "<R>" . "合计：" . $order['total_pay_price'] . "元" . "<BR></R>";

        $printContent = $printContent . "<BR>";
        $printContent = $printContent . "<L>"
//          . "客户地址：" . "珠海市香洲区xx路xx号" . "<BR>"
            . "订单编号：" . $osn . "<BR>"
            . "下单时间：" . date("Y-m-d H:i") . "<BR>";
//          . "备注：" . "少放辣 不吃香菜" . "<BR>";

        $printContent = $printContent . "<C>"
            . "<QR>https://www.xpyun.net</QR>"
            . "</C>";


        $request = new PrintRequest();
        $request->generateSign();

        //*必填*：打印机编号
        $request->sn = '02QTZFKEUGC4449';

        //*必填*：打印内容,不能超过12K
        $request->content = $printContent;

        //打印份数，默认为1
        $request->copies = 1;

        //声音播放模式，0 为取消订单模式，1 为静音模式，2 为来单播放模式，3为有用户申请退单了。默认为 2 来单播放模式
        $request->voice = 1;
        //打印模式：
        //值为 0 或不指定则会检查打印机是否在线，如果不在线 则不生成打印订单，直接返回设备不在线状态码；如果在线则生成打印订单，并返回打印订单号。
        //值为 1不检查打印机是否在线，直接生成打印订单，并返回打印订单号。如果打印机不在线，订单将缓存在打印队列中，打印机正常在线时会自动打印。
        $request->mode = 1;
        
        
        //支付方式：
        //取值范围41~55：
        //支付宝 41、微信 42、云支付 43、银联刷卡 44、银联支付 45、会员卡消费 46、会员卡充值 47、翼支付 48、成功收款 49、嘉联支付 50、壹钱包 51、京东支付 52、快钱支付 53、威支付 54、享钱支付 55
        //仅用于支持金额播报的芯烨云打印机。
        $request->payType = 41;

        //支付与否：
        //取值范围59~61：
        //退款 59 到账 60 消费 61。
        //仅用于支持金额播报的芯烨云打印机。
        $request->payMode = 60;

        //支付金额：
        //最多允许保留2位小数。
        //仅用于支持金额播报的芯烨云打印机。
        $request->money = 20.15;
        
        
        $service = new PrintService();
        $result = $service->xpYunPrint($request);
        if($order['pay_type'] == 5)$service->xpYunControlBox($request);
//      echo json_encode($request);
//        print $result->content->code . "\n";
//        print $result->content->msg . "\n";
//
//        //data:正确返回订单编号
//        print $result->content->data . "\n";
    }
    
    public function refundnotify()
    {
    	$response = $this->request->post('response');
        $customerIdentification = $this->request->post('customerIdentification');
         /*商户私钥*/
        $private_key ="MIIEugIBADANBgkqhkiG9w0BAQEFAASCBKQwggSgAgEAAoIBAQCQMqL/T97RhAophQNRzBwE+vU+59PzfkEzyLZwMaQTduHvdTl4fg6KZ6ATFUgECI2JLpZq3cyjVYSlM9H20bRpZSaoYmsYyNibpf2lg+bMg9G+bS6elHvFn0ZJ+aU40wyWqPjtdLB9JYLDbLVsb6SzHegWovWeWD7vUqCbPhDK24V///baX2zV4609kfa1iBGbynF/0nggHw3leeUW9F8E8twSEF15ObE8ShywOMvi578kv9PUNmSiq8gfc/t8dWVOzi4mbDje49MhxMbuopGv1kcvHBrThTeqQ2plhQSs63AbwLpe4WsZbcNvG9zpjuci8bK1+Zb/3DnkmT4zEu6FAgMBAAECggEAHsQfEPhaoztX67nslmRFSi69atmN2HMEuGbHvjJpPpnr5OqPA41pztADU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ju6FGhDgoB98rihcaUlsJfoTvrSmkLAmQOH8DW+a0UVbcCMp7TtWgpC8UMT0adAb/4ngQhjYuED4pI=";
        $yopPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6p0XWjscY+gsyqKRhw9MeLsEmhFdBRhT2emOck/F1Omw38ZWhJxh9kDfs5HzFJMrVozgU+SJFDONxs8UB0wMILKRmqfLcfClG9MyCNuJkkfm0HFQv1hRGdOvZPXj3Bckuwa7FrEXBRYUhK7vJ40afumspthmse6bs6mZxNn/mALZ2X07uznOrrc2rk41Y2HftduxZw6T4EmtWuN2x4CZ8gwSyPAW5ZzZJLQ6tZDojBK4GZTAGhnn3bg5bBsBlw2+FLkCQBuDsJVsFPiGh/b6K/+zGTvWyUcu+LUj2MejYQELDO3i2vQXVDk7lVi2/TcUYefvIcssnzsfCfjaorxsuwIDAQAB";
        $decryptresponse = YopSignUtils::decrypt($response,$private_key,$yopPublicKey);

        $decrypt = json_decode($decryptresponse);
         $response = json_encode($response);
             YeeRepose::create([
            'response' => $response,
            'customer' => $customerIdentification,
            'dec' =>$decryptresponse,
            'type' =>5,
        ]);

        if($decrypt->status == 'SUCCESS')
	    {
	    	$order = Order::where('order_no', $decrypt->orderId)->find();
	    	
        	if($order&&$order['is_pay'] == 2)
        	{
        		Order::where('order_no', $decrypt->orderId)->update(['is_pay' => 1,'status'=> 2]);
        		if($order['type'] == 1)
        		{
        			Orderrecharge::where('order_no', $decrypt->orderId)->update(['is_pay'=>1,'status'=> 2]);
        		}
        		if($order['type'] == 2)Ordergas::where('order_no', $decrypt->orderId)->update(['is_pay'=>1,'status'=> 2]);
        		if($order['type'] == 3)Ordergoods::where('order_no', $decrypt->orderId)->update(['is_pay'=>1,'status'=> 2]);
        		if($order['type'] == 4){
        			Ordergas::where('order_no', $decrypt->orderId)->update(['is_pay'=>1,'status'=> 2]);
        			Ordergoods::where('order_no', $decrypt->orderId)->update(['is_pay'=>1,'status'=> 2]);
        		}
        	}
	    }
        
   
        echo 'OK';
    }
    
//  # 计算两点之间距离
	public function getDistance($lat1, $lng1, $lat2, $lng2)
	{
	    $radLat1 = deg2rad(floatval($lat1));// deg2rad()函数将角度转换为弧度
	    $radLat2 = deg2rad(floatval($lat2));
	    $radLng1 = deg2rad(floatval($lng1));
	    $radLng2 = deg2rad(floatval($lng2));
	    $a = $radLat1 - $radLat2;
	    $b = $radLng1 - $radLng2;
	    $s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))) * 6378.137;
//	    if ($s * 1000 < 1000) {
//	        return round($s * 1000, 2) . "m";
//	    } else {
//	        return round($s, 2) . "km";
//	    }
        return round($s * 1000, 2);
	}
	public function getDis()
    {
    	$store_no = $this->request->post('store_no');
    	$lat = $this->request->post('lat');
    	$lng = $this->request->post('lng');
        $visil = true;
    	$storeinfo = Storeset::where('store_no',$store_no)->find();
    	$storeset = StoreConfig::where('name','gap')->where('store_no',$store_no)->find();

    	$ju = $this->getDistance($lat,$lng,$storeinfo['latitude'],$storeinfo['longitude']);
    	if($storeset['value']>0&&$storeset['value']<$ju&&$storeset['value']>0)
    	{
    		$visil = false;
    	}
    	$data['distan'] = $ju;
        $data['visil'] = $visil;
        $this->success('获取成功',$data);
    }
    
             /**
     * 推送油品数据
     *
     */
    public function sendoildata()
    {
        $store_no = $this->request->post('store_no');
    	$serno = $this->request->post('serno');//2加油  3 商品
    	$gasno = $this->request->post('gasno');
    	$gasgun = $this->request->post('gasgun');//商品商量
    	$price = $this->request->post('price');//订单总额
    	$num = $this->request->post('num');//订单总额
    	$all_money = $this->request->post('all_money');
    	if($store_no == 1)$store_no = 1;
    	if($store_no == 2)$store_no = 98096;
    	$storeinfo = Oilorder::where('store_no',$store_no)->where('serno',$serno)->find();
    	if($storeinfo)$this->error('已推送');
    	$stainfo = Station::where('store_no', $store_no)->find();
    	if(!$stainfo)$this->error('店铺不存在');
    	
    	        $params['serno']=$serno;
		        $params['gasno']=$gasno;
		        $params['gasgun']=$gasgun;
		        $params['price']=$price;
		        $params['num']=$num;
		        $params['all_money']=$all_money;
		        $params['agent_id']=$stainfo['agent_id'];
		        $params['store_no']=$store_no;
		        $params['status']=0;
		        $params['addtime']=time();
		    
		    	$result = Oilorder::create($params);
		    	
		$this->success('推送成功');
    }
    
    
             /**
     * 获取改价信息
     *
     */
    public function getchangeprice()
    {
        $store_no = $this->request->post('store_no');

    	if($store_no == 1)$store_no = 1;
    	if($store_no == 2)$store_no = 98096;
    	
    	$data = Gasgun::where('store_no', $store_no)->select();
    	$gasInfo = array();
    	if($data)
    	{
    		foreach ($data as $index => $item) {
    			
    			$info = Oilprice::where('store_no', $store_no)->where('gas_id', $item['gas_id'])->where('status', 3)->find();
    			if(!$info)continue;
    		
//  			$gasInfo['gun_no'] = $this->findNum($item['name']);
//	    	    $gasInfo['price'] = $info['local_price'];
	    	    
	    	    $gasInfo[] = array('gun_no' =>$this->findNum($item['name']), 'price' => $info['local_price'], 'id' => $info['id']);

	    	}
    	}
        $this->success('获取成功',$gasInfo);
    }
    
      
             /**
     * 更改调价记录状态
     *
     */
    public function changestatus()
    {
        $store_no = $this->request->post('store_no');
        $id = $this->request->post('id');
    	if($store_no == 1)$store_no = 1;
    	if($store_no == 2)$store_no = 98096;
    	
    	$data = Oilprice::where('store_no', $store_no)->where('id', $id)->update(['status' => 2]);

        $this->success('修改成功');
    }
    
               /**
     * 获取加油数据
     *
     */
    public function getoilorder()
    {
    	$store_no = $this->request->post('store_no');
    	$gasgun = $this->request->post('gasgun');
    	$oilinfo = Oilorder::where('store_no',$store_no)->where('gasgun',$gasgun)->where('status',0)->order('id desc')->find();

        $this->success('请求成功',$oilinfo);
    }
    
    public function findNum($str=”){
	    $str=trim($str);
    if(empty($str))return '';
			    $temp=array('1','2','3','4','5','6','7','8','9','0');
			    $result="";
			    for($i=0;$i<strlen($str);$i++){
			        if(in_array($str[$i],$temp)){
			            $result.=$str[$i];
			        }
			    }
			    return $result;
	}
	
	 public function staticnotify()
    {
    	$response = $this->request->post('response');
        $customerIdentification = $this->request->post('customerIdentification');
         /*商户私钥*/
        $private_key ="MIIEugIBADANBgkqhkiG9w0BAQEFAASCBKQwggSgAgEAAoIBAQCQMqL/T97RhAophQNRzBwE+vU+59PzfkEzyLZwMaQTduHvdTl4fg6KZ6ATFUgECI2JLpZq3cyjVYSlM9H20bRpZSaoYmsYyNibpf2lg+bMg9G+bS6elHvFn0ZJ+aU40wyWqPjtdLB9JYLDbLVsb6SzHegWovWeWD7vUqCbPhDK24V///baX2zV4609kfa1iBGbynF/0nggHw3leeUW9F8E8twSEF15ObE8ShywOMvi578kv9PUNmSiq8gfc/t8dWVOzi4mbDje49MhxMbuopGv1kcvHBrThTeqQ2plhQSs63AbwLpe4WsZbcNvG9zpjuci8bK1+Zb/3DnkmT4zEu6FAgMBAAECggEAHsQfEPhaoztX67nslmRFSi69atmN2HMEuGbHvjJpPpnr5OqPA41pztADUG8G+Y1VnYJqJ40BX4wcjB79Wnst0hr53414KkaYKMWG0+zLrrElbErhWoZ1zhmIprn0LaaiFfchfZCbI2iAeO/V2bgMXQcxgLruSwWrD+cCS303mgBgW7tWsqlfplLvtWqJBWyA4Y8ObV/RUuLjr38Q8nCGZ81ep+De0euDkV4JQ/tg7uQEvEAOwpB6EEBwYt8GZVwcq8SWfP1cOw0Q7hkvn+rHvnXa2MHg8pdQHOfigvHr4Z5udkSiM885Pbjyh6H+UldtKFx2pW9EoD4t37CMwjeJtQKBgQDMWc00sfln9lRUBarV0D7fL6Z8/kueyBaTXFrzauHGwqK9KvB9ADmqFuBxZij8fJBkQyQtgNgbutTqgo0BJgTB2Q5lH097SBUdrTUrJdo3+rKY4/fbQBU7zF9oQ2p+dyFHmW/zjjWALnQYchd1lsZGkrSg2qPto/PRttkES/jrywKBgQC0pLrjcQ+6XZAUie+wSML+f/zGvxw1821Tn8poe0FIaX7/vPhRo028eF+R4Kav/yiVxeTAzk1D5OtN0Q3XO/nIY6f68WbdjBeFFSyovpPi1GX8kSys5wIo79nNnF/cEIJMTnvmyn51RaH8jtSVhshqqzHdesezXTYV3lwg4Urk7wKBgFqKS0ZWuIdcd76GiEuVqdWfOifVT9H5Gy+NUurY51H2OL6RwN3RdLssyaLUvcIoup0BtozGsnmOzPlegHUK0D7HGf6p4cBgjqKIdK86ZTY6SFk/YDjvarkE8xyyCgQgaklb7WM/FetGKcAPBN/fvtfT9l3yoYEQDF5Vok+qDY8DAn80N2nOVOA2/tSnGzgtvNqgtl5bFOMStUrk4Uug5//27ofHZNhiwNG3qRP3FvkX5qnUoV9+XCP5fDKIS+W0UaHiSuxDnYQehmBGF9jQ7kXRS5Qvbcd8M0psiuhqhsku05bWd9lY3S+wtnAckSziDBPiwZmoa9VOA6Oerqfy2SzNAoGAETFFK7YKO6+fGNJv5M5KJuZsOGkqgmfkJhAOnC2wLPDMMFDXnWG+oPcI6bosyvM+I8FDqwE3VcbmFlEJPnC4hQvwK3JjAju6FGhDgoB98rihcaUlsJfoTvrSmkLAmQOH8DW+a0UVbcCMp7TtWgpC8UMT0adAb/4ngQhjYuED4pI=";
        $yopPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6p0XWjscY+gsyqKRhw9MeLsEmhFdBRhT2emOck/F1Omw38ZWhJxh9kDfs5HzFJMrVozgU+SJFDONxs8UB0wMILKRmqfLcfClG9MyCNuJkkfm0HFQv1hRGdOvZPXj3Bckuwa7FrEXBRYUhK7vJ40afumspthmse6bs6mZxNn/mALZ2X07uznOrrc2rk41Y2HftduxZw6T4EmtWuN2x4CZ8gwSyPAW5ZzZJLQ6tZDojBK4GZTAGhnn3bg5bBsBlw2+FLkCQBuDsJVsFPiGh/b6K/+zGTvWyUcu+LUj2MejYQELDO3i2vQXVDk7lVi2/TcUYefvIcssnzsfCfjaorxsuwIDAQAB";
        $decryptresponse = YopSignUtils::decrypt($response,$private_key,$yopPublicKey);

        $decrypt = json_decode($decryptresponse);
         $response = json_encode($response);
             YeeRepose::create([
            'response' => $response,
            'customer' => $customerIdentification,
            'dec' =>$decryptresponse,
            'type' =>7,
        ]);

        if($decrypt->status == 'SUCCESS')
	    {
	    	$order = Order::where('order_no', $decrypt->orderId)->find();
	    	
        	if($order&&$order['is_pay'] == 0)
        	{
        		Order::where('order_no', $decrypt->orderId)->update(['is_pay' => 2]);
        		if($order['type'] == 1)
        		{
        			Orderrecharge::where('order_no', $decrypt->orderId)->update(['is_pay'=>2]);
        			UserDetail::where('id',$order['user_id'])->setInc('money', $order['total_pay_price']+$order['gift_amount']);
        		}
        		if($order['type'] == 2)Ordergas::where('order_no', $decrypt->orderId)->update(['is_pay'=>2]);
        		if($order['type'] == 3)Ordergoods::where('order_no', $decrypt->orderId)->update(['is_pay'=>2]);
        		if($order['type'] == 4){
        			Ordergas::where('order_no', $decrypt->orderId)->update(['is_pay'=>2]);
        			Ordergoods::where('order_no', $decrypt->orderId)->update(['is_pay'=>2]);
        		}
        	}
	    }
        
   
        echo 'OK';
    }
    
    public function clearnotify()
    {
    	$response = $this->request->post('response');
        $customerIdentification = $this->request->post('customerIdentification');
         /*商户私钥*/
        $private_key ="MIIEugIBADANBgkqhkiG9w0BAQEFAASCBKQwggSgAgEAAoIBAQCQMqL/T97RhAophQNRzBwE+vU+59PzfkEzyLZwMaQTduHvdTl4fg6KZ6ATFUgECI2JLpZq3cyjVYSlM9H20bRpZSaoYmsYyNibpf2lg+bMg9G+bS6elHvFn0ZJ+aU40wyWqPjtdLB9JYLDbLVsb6SzHegWovWeWD7vUqCbPhDK24V///baX2zV4609kfa1iBGbynF/0nggHw3leeUW9F8E8twSEF15ObE8ShywOMvi578kv9PUNmSiq8gfc/t8dWVOzi4mbDje49MhxMbuopGv1kcvHBrThTeqQ2plhQSs63AbwLpe4WsZbcNvG9zpjuci8bK1+Zb/3DnkmT4zEu6FAgMBAAECggEAHsQfEPhaoztX67nslmRFSi69atmN2HMEuGbHvjJpPpnr5OqPA41pztADUG8G+Y1VnYJqJ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UlsJfoTvrSmkLAmQOH8DW+a0UVbcCMp7TtWgpC8UMT0adAb/4ngQhjYuED4pI=";
        $yopPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6p0XWjscY+gsyqKRhw9MeLsEmhFdBRhT2emOck/F1Omw38ZWhJxh9kDfs5HzFJMrVozgU+SJFDONxs8UB0wMILKRmqfLcfClG9MyCNuJkkfm0HFQv1hRGdOvZPXj3Bckuwa7FrEXBRYUhK7vJ40afumspthmse6bs6mZxNn/mALZ2X07uznOrrc2rk41Y2HftduxZw6T4EmtWuN2x4CZ8gwSyPAW5ZzZJLQ6tZDojBK4GZTAGhnn3bg5bBsBlw2+FLkCQBuDsJVsFPiGh/b6K/+zGTvWyUcu+LUj2MejYQELDO3i2vQXVDk7lVi2/TcUYefvIcssnzsfCfjaorxsuwIDAQAB";
        $decryptresponse = YopSignUtils::decrypt($response,$private_key,$yopPublicKey);

        $decrypt = json_decode($decryptresponse);
         $response = json_encode($response);
             YeeRepose::create([
            'response' => $response,
            'customer' => $customerIdentification,
            'dec' =>$decryptresponse,
            'type' =>7,
        ]);

        if($decrypt->status == 'SUCCESS')
	    {
	    	$order = Order::where('order_no', $decrypt->orderId)->find();
	    	
        	if($order&&$order['is_pay'] == 0)
        	{
        		Order::where('order_no', $decrypt->orderId)->update(['is_pay' => 2]);
        		if($order['type'] == 1)
        		{
        			Orderrecharge::where('order_no', $decrypt->orderId)->update(['is_pay'=>2]);
        			UserDetail::where('id',$order['user_id'])->setInc('money', $order['total_pay_price']+$order['gift_amount']);
        		}
        		if($order['type'] == 2)Ordergas::where('order_no', $decrypt->orderId)->update(['is_pay'=>2]);
        		if($order['type'] == 3)Ordergoods::where('order_no', $decrypt->orderId)->update(['is_pay'=>2]);
        		if($order['type'] == 4){
        			Ordergas::where('order_no', $decrypt->orderId)->update(['is_pay'=>2]);
        			Ordergoods::where('order_no', $decrypt->orderId)->update(['is_pay'=>2]);
        		}
        	}
	    }
        
   
        echo 'OK';
    }
    public function shareorder()
    {
    	$private_key ="MIIEugIBADANBgkqhkiG9w0BAQEFAASCBKQwggSgAgEAAoIBAQCQMqL/T97RhAophQNRzBwE+vU+59PzfkEzyLZwMaQTduHvdTl4fg6KZ6ATFUgECI2JLpZq3cyjVYSlM9H20bRpZSaoYmsYyNibpf2lg+bMg9G+bS6elHvFn0ZJ+aU40wyWqPjtdLB9JYLDbLVsb6SzHegWovWeWD7vUqCbPhDK24V///baX2zV4609kfa1iBGbynF/0nggHw3leeUW9F8E8twSEF15ObE8ShywOMvi578kv9PUNmSiq8gfc/t8dWVOzi4mbDje49MhxMbuopGv1kcvHBrThTeqQ2plhQSs63AbwLpe4WsZbcNvG9zpjuci8bK1+Zb/3DnkmT4zEu6FAgMBAAECggEAHsQfEPhaoztX67nslmRFSi69atmN2HMEuGbHvjJpPpnr5OqPA41pztADUG8G+Y1VnYJqJ40BX4wcjB79Wnst0hr53414KkaYKMWG0+zLrrElbErhWoZ1zhmIprn0LaaiFfchfZCbI2iAeO/V2bgMXQcxgLruSwWrD+cCS303mgBgW7tWsqlfplLvtWqJBWyA4Y8ObV/RUuLjr38Q8nCGZ81ep+De0euDkV4JQ/tg7uQEvEAOwpB6EEBwYt8GZVwcq8SWfP1cOw0Q7hkvn+rHvnXa2MHg8pdQHOfigvHr4Z5udkSiM885Pbjyh6H+UldtKFx2pW9EoD4t37CMwjeJtQKBgQDMWc00sfln9lRUBarV0D7fL6Z8/kueyBaTXFrzauHGwqK9KvB9ADmqFuBxZij8fJBkQyQtgNgbutTqgo0BJgTB2Q5lH097SBUdrTUrJdo3+rKY4/fbQBU7zF9oQ2p+dyFHmW/zjjWALnQYchd1lsZGkrSg2qPto/PRttkES/jrywKBgQC0pLrjcQ+6XZAUie+wSML+f/zGvxw1821Tn8poe0FIaX7/vPhRo028eF+R4Kav/yiVxeTAzk1D5OtN0Q3XO/nIY6f68WbdjBeFFSyovpPi1GX8kSys5wIo79nNnF/cEIJMTnvmyn51RaH8jtSVhshqqzHdesezXTYV3lwg4Urk7wKBgFqKS0ZWuIdcd76GiEuVqdWfOifVT9H5Gy+NUurY51H2OL6RwN3RdLssyaLUvcIoup0BtozGsnmOzPlegHUK0D7HGf6p4cBgjqKIdK86ZTY6SFk/YDjvarkE8xyyCgQgaklb7WM/FetGKcAPBN/fvtfT9l3yoYEQDF5Vok+qDY8DAn80N2nOVOA2/tSnGzgtvNqgtl5bFOMStUrk4Uug5//27ofHZNhiwNG3qRP3FvkX5qnUoV9+XCP5fDKIS+W0UaHiSuxDnYQehmBGF9jQ7kXRS5Qvbcd8M0psiuhqhsku05bWd9lY3S+wtnAckSziDBPiwZmoa9VOA6Oerqfy2SzNAoGAETFFK7YKO6+fGNJv5M5KJuZsOGkqgmfkJhAOnC2wLPDMMFDXnWG+oPcI6bosyvM+I8FDqwE3VcbmFlEJPnC4hQvwK3JjAju6FGhDgoB98rihcaUlsJfoTvrSmkLAmQOH8DW+a0UVbcCMp7TtWgpC8UMT0adAb/4ngQhjYuED4pI=";
			
		$request = new YopRequest("app_10088909942", $private_key);
			        $osn = date('YmdHis') . rand(10000000,99999999);
			        $divideDetail = array();
			        $divideDetail[] = array(
			                'amount'   	   => '0.5',
			                'ledgerNo'     => '10089018690',
			
			            );     
//			             $this->success('请求成功',$divideDetail);
			        $divideDetail = json_encode($divideDetail);
        
			        //加入请求参数
			        $request->addParam("parentMerchantNo",'10088970121');
			        $request->addParam("merchantNo",'10088970121');
			        $request->addParam("orderId",'2304043306090549472');
			        $request->addParam("uniqueOrderNo",'1013202304040000005849892883');
			        $request->addParam("divideRequestId",'YBRWQQH'.time());
			        $request->addParam("divideDetail",$divideDetail);

			//      //提交Post请求
			        $response = YopRsaClient::post("/rest/v1.0/divide/apply", $request);
//                  $response = json_decode($response,true);
                    
                    $this->success('请求成功',$response);
	}
    
}
